import 'package:flutter/material.dart';
import 'package:flutter_yn_goods/user/app_user_manager.dart';
import 'package:flutter_yn_goods/utils/loading/loading_utils.dart';
import 'package:get/get.dart';

class ModifyAddressLogic extends GetxController {
  TextEditingController textEditingController = TextEditingController();
  var buttonEnable = false.obs;

  void onTextChanged() {
    buttonEnable.value =
        textEditingController.text.trim().length > 3 ;
  }

  // String province = (AppUserManager().user.value?.province ?? '').toString();
  // String city = (AppUserManager().user.value?.city ?? '').toString();
  // String area = (AppUserManager().user.value?.area ?? '').toString();
  // String cityName = (AppUserManager().user.value?.cityName ?? '').toString();

  @override
  void onReady() {
    // TODO: implement onReady
    super.onReady();
  }

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    textEditingController.text =
        (AppUserManager().user.value?.address ?? '').toString();
  }

  @override
  void onClose() {
    // TODO: implement onClose
    super.onClose();
    textEditingController.dispose();
  }

  void saveAddress() async {
    // String name = textEditingController.text;
    // if(initName==name){
    //   Get.back();
    // }else{
    var response = await AppUserManager().saveUserInfo(
        // cityName: cityName,
        // province: province,
        // city: city,
        // area: area,
        address: textEditingController.text.trim(),
        showLoading: true);
    if (response.isSuccess) {
      Get.back();
    } else {
      LoadingUtils.showToast(response.codeAndMsg);
    }
    // }
  }
}
